<%--
  Created by IntelliJ IDEA.
  User: dzw
  Date: 2017/12/12
  Time: 10:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  String jsessionid = session.getId();
%>

<div class="panel">
  <div class="panel-heading header">
    <h3 class="panel-title" id="title">离职申请</h3>
  </div>

  <!-- BASIC FORM ELEMENTS -->
  <!--===================================================-->
  <form id="form_quit_input" class="form-horizontal">

    <input type="hidden" name="keyId" id="keyId" value="${quit.id}"/>

    <div class="form-group">
      <label class="col-md-2 control-label">
        <a href="javascript:void(0);" onclick="fn_member_dialog_select('quitUser', 'quitUserId')" style="color: #4FA5D0">离职人员</a>
        <i class="fa fa-asterisk txt-color-red"></i>
      </label>
      <div class="col-md-6">
        <input type="text" id="quitUser" class="form-control" placeholder="请选择离职人员" readonly value="${quit.quitUser.name}" onclick="fn_member_dialog_select('quitUser', 'quitUserId')" >
        <input type="hidden" id="quitUserId" name="quitUserId" value="${quit.quitUser.id}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">入职日期<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input placeholder="请选择入职日期" id="entryDate" name="entryDate" class="form-control quitDate" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${quit.entryDate}" />">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">离职日期<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input placeholder="请选择离职日期" id="quitDate" name="quitDate" class="form-control quitDate" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${quit.quitDate}" />">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">
        <a href="javascript:void(0);" onclick="fn_post_dialog_select('thePost', 'thePostId')" style="color: #4FA5D0">所属岗位</a>
        <i class="fa fa-asterisk txt-color-red"></i>
      </label>
      <div class="col-md-6">
        <input type="text" id="thePost" class="form-control" placeholder="请选择所属岗位" readonly value="${quit.thePost.name}" onclick="fn_post_dialog_select('thePost', 'thePostId')" >
        <input type="hidden" id="thePostId" name="thePostId" value="${quit.thePost.id}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">
        <a href="javascript:void(0);" onclick="fn_member_dialog_select('nextUser', 'nextUserId')" style="color: #4FA5D0">交接人员</a>
        <i class="fa fa-asterisk txt-color-red"></i>
      </label>
      <div class="col-md-6">
        <input type="text" id="nextUser" class="form-control" placeholder="请选择交接人员" readonly value="${quit.nextUser.name}" onclick="fn_member_dialog_select('nextUser', 'nextUserId')" >
        <input type="hidden" id="nextUserId" name="nextUserId" value="${quit.nextUser.id}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">劳动合同开始日期<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input placeholder="请选择劳动合同开始日期" id="contractStartDate" name="contractStartDate" class="form-control quitDate" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${quit.contractStartDate}" />">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">劳动合同结束日期<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input placeholder="请选择劳动合同结束日期" id="contractEndDate" name="contractEndDate" class="form-control quitDate" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${quit.contractEndDate}" />">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">离职原因<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input type="text" name="quitReason" id="quitReason" class="form-control" placeholder="请输入离职原因" value="${quit.quitReason}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">所需交接事项<i class="fa fa-asterisk txt-color-red"></i></label>
      <div class="col-md-6">
        <input type="text" name="theThing" id="theThing" class="form-control" placeholder="请输入所需交接事项" value="${quit.theThing}">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">
        是否抄送
      </label>
      <div class="col-md-6">
        <div class="radio">
          <input type="radio" id="remindYes" name="remind" value="1" class="magic-radio">
          <label for="remindYes">是</label>
          <input type="radio" id="remindNo" name="remind" value="0" class="magic-radio">
          <label for="remindNo">否</label>
        </div>
      </div>
    </div>

    <div class="form-group" style="display: none" id="showRemind">
      <label class="col-md-2 control-label">
        <a href="javascript:void(0);" onclick="fn_members_dialog_select('remindUser', 'remindUserId')" style="color: #4FA5D0">抄送人员</a>
        <i class="fa fa-asterisk txt-color-red"></i>
      </label>
      <div class="col-md-6">
        <input type="text" id="remindUser" name="remindUser" class="form-control" placeholder="请选择抄送人员" readonly value="" onclick="fn_members_dialog_select('remindUser', 'remindUserId')">
        <input type="hidden" id="remindUserId" name="remindUserId" value="">
      </div>
    </div>

    <div class="form-group">
      <label class="col-md-2 control-label">
        下一步流程
      </label>
      <div class="col-md-6">
        <div class="radio">
          <input type="radio" id="nextNo" name="next" value="0" class="magic-radio">
          <label for="nextNo">归档</label>
          <input type="radio" id="nextYes" name="next" value="1" class="magic-radio">
          <label for="nextYes">选择下一步操作人</label>
        </div>
      </div>
    </div>

    <div class="form-group" style="display:none" id="showNextStep">
      <label class="col-md-2 control-label">
        <a href="javascript:void(0);" onclick="fn_member_dialog_select('editors', 'editorsId')" style="color: #4FA5D0">选择下一步操作人</a>
        <i class="fa fa-asterisk txt-color-red"></i>
      </label>
      <div class="col-md-6">
        <input type="text" id="editors" name="editors" class="form-control" placeholder="请选择下一步操作人" readonly onclick="fn_member_dialog_select('editors', 'editorsId')" >
        <input type="hidden" id="editorsId" name="editorsId">
      </div>
    </div>

  </form>
  <!--===================================================-->
  <!-- END BASIC FORM ELEMENTS -->

  <div class="panel-footer">
    <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
      <i class="fa fa-lg fa-mail-reply"></i> 返回
    </a>
    <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
    <c:if test="${quit==null || quit.processState=='Draft'}">
      <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
    </c:if>
    <c:if test="${quit!=null && quit.processState=='Backed'}">
      <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
    </c:if>
  </div>
</div>

<script>
  var index = "${index}";
  var todo = "${todo}";
  var remind = "${remind}";
  var record = "${record}";
  var draft =  "${draft}";

  $(function(){
    fn_quit_input_validate()
  });

  //下一步点击
  $(':radio[name="next"]').click(function(){
    if($(this).val() == "1"){
      $('#showNextStep').show();
    }else{
      $('#showNextStep').hide();
    }
  });

  //抄送点击
  $(':radio[name="remind"]').click(function(){
    if($(this).val() == "1"){
      $('#showRemind').show();
    }else{
      $('#showRemind').hide();
    }
  });

  $('.quitDate').datepicker({
    format: 'yyyy-mm-dd',
    weekStart: 1,
    autoclose: true,
    todayBtn: 'linked',
    todayHighlight: true,
    language: 'zh-CN'
  });

  //岗位选择框(单选)
  function fn_post_dialog_select(nameField,idField) {
    __open_dialog_select('选择岗位', '<%=path%>/com/quit/postDialog', function (dialogRef) {
      var callback = function (data) {
        if (data) {
          dialogRef.close();
          $('#'+idField).val(data.id);
          $('#'+nameField).val(data.name);
        } else {
          dialogRef.enableButtons();
        }
      };
      fn_dialog_post_select(callback);
    });
  }

  // 表单数据校验
  function fn_quit_input_validate() {
    __init_validate('form_quit_input', {
      rules : {
        quitUserId : {
          required : true
        },
        startDate : {
          required : true
        },
        endDate : {
          required : true
        },
        reason : {
          required : true
        },
        startTime:{
          required : true
        },
        endTime:{
          required : true
        },
        next:{
          required:true
        },
        editorsId:{
          required:function(){
            if($(':checked[name="next"]').val() == "1"){
              return true;
            }else{
              return false;
            }
          }
        }
      },
      messages : {
        quitUserId : {
          required : "请选择离职人员"
        },
        startDate : {
          required : "请选择离职开始日期"
        },
        endDate : {
          required : "请选择离职结束日期"
        },
        reason : {
          required : "请输入离职事由"
        },
        startTime : {
          required : "请选择离职开始时间"
        },
        endTime : {
          required : "请选择离职结束时间"
        },
        next:{
          required : "请选择下一步流程"
        },
        editorsId : {
          required : "请选择下一步操作人"
        }
      }
    });
  }

  //保存
  $("#btn-save-common").click(function(){
    __confirm_dialog("提示","确定保存吗？",function(){
      __form_save("form_quit_input", "<%=path%>/com/quit/save",function(){
        $("#apply-re-common").trigger("click");
      })
    })
  });

  //提交
  $("#btn-commit-common,#btn-recommit-common").click(function(){
    if (!$('#form_quit_input').valid()) {
      return false;
    }
    __confirm_dialog("提示","确定提交吗？",function(){
      __form_save("form_quit_input", "<%=path%>/com/quit/commit",function(){
        $("#apply-re-common").trigger("click");
      })
    })
  });


  //返回视图
  $("#apply-re-common").click(function(){
    if(index==1){
      loadURL("menu/dashboard",$('#page-content'));
    }else if(todo==1){
      loadURL("menu/toDo",$('#page-content'));
    }else if(remind==1){
      loadURL("menu/remind",$('#page-content'));
    }else if(record==1){
      loadURL("menu/taskRecord?type=1",$('#page-content'));
    }else if(record==2){
      loadURL("menu/taskRecord?type=2",$('#page-content'));
    }else if(draft==1){
      loadURL("menu/draft",$('#page-content'));
    }else{
      returnToHashUrl()
    }
  });

</script>